package com.itrip.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itrip.common.Page;
import com.itrip.entity.ItripHotelOrder;
import com.itrip.vo.order.ItripListHotelOrderVO;
import com.itrip.vo.order.ItripPersonalOrderRoomVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface ItripHotelOrderMapper extends BaseMapper<ItripHotelOrder>{
       @Select("<script> select\n" +
               "    o.id AS id,\n" +
               "    o.hotelId AS hotelId,\n" +
               "    o.hotelName AS hotelName,\n" +
               "    h.hotelLevel AS hotelLevel,\n" +
               "    h.address AS address,\n" +
               "    o.roomId AS roomId,\n" +
               "    r.roomTitle AS roomTitle,\n" +
               "    r.roomBedTypeId AS roomBedTypeId,\n" +
               "    o.count AS count,\n" +
               "    o.bookingDays AS bookingDays,\n" +
               "    o.checkInDate AS checkInDate,\n" +
               "    o.checkOutDate AS checkOutDate,\n" +
               "    o.specialRequirement AS specialRequirement,\n" +
               "    o.linkUserName AS linkUserName,\n" +
               "    o.payAmount AS payAmount,\n" +
               "    r.payType AS roomPayType,\n" +
               "    d.name as roomBedTypeName,\n" +
               "    r.isHavingBreakfast as isHavingBreakfast,\n" +
               "    dayofweek(o.checkInDate) as checkInWeek,\n" +
               "    dayofweek(o.checkOutDate) as checkOutWeek\n" +
               "    from itrip_hotel_order o,itrip_hotel h,itrip_hotel_room r,itrip_label_dic d\n" +
               "    <trim prefix=\"where\" prefixOverrides=\"and | or\">\n" +
               "        o.hotelId=h.id and o.roomId=r.id and d.id=r.roomBedTypeId\n" +
               "        <if test=\"id != null\">\n" +
               "            and o.id=#{id}\n" +
               "        </if>\n" +
               "    </trim> </script>")
       public ItripPersonalOrderRoomVO getItripHotelOrderRoomInfoById(Long id);

       public Page<ItripListHotelOrderVO> queryOrderPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize);
       @Select(" <script> select count(*) from itrip_hotel_order\n" +
               "    <trim prefix=\"where\" prefixOverrides=\"and | or\">\n" +
               "        <if test=\"id != null and id!=''\">\n" +
               "            and id=#{id}\n" +
               "        </if>\n" +
               "        <if test=\"userId != null and userId!=''\">\n" +
               "            and userId=#{userId}\n" +
               "        </if>\n" +
               "        <if test=\"orderType != null\">\n" +
               "            and orderType=#{orderType}\n" +
               "        </if>\n" +
               "        <if test=\"orderNo != null and orderNo!=''\">\n" +
               "            and orderNo like CONCAT ('%',#{orderNo},'%')\n" +
               "        </if>\n" +
               "        <if test=\"hotelId != null and hotelId!=''\">\n" +
               "            and hotelId=#{hotelId}\n" +
               "        </if>\n" +
               "        <if test=\"hotelName != null and hotelName!=''\">\n" +
               "            and hotelName=#{hotelName}\n" +
               "        </if>\n" +
               "        <if test=\"checkInDate != null and checkInDate!=''\">\n" +
               "            and checkInDate=#{checkInDate}\n" +
               "        </if>\n" +
               "        <if test=\"orderStatus != null\">\n" +
               "            and orderStatus=#{orderStatus}\n" +
               "        </if>\n" +
               "        <if test=\"payAmount != null and payAmount!=''\">\n" +
               "            and payAmount=#{payAmount}\n" +
               "        </if>\n" +
               "        <if test=\"linkUserName != null and linkUserName != ''\">\n" +
               "            and linkUserName like CONCAT ('%',#{linkUserName},'%')\n" +
               "        </if>\n" +
               "        <if test=\"startDate != null and startDate!=''\">\n" +
               "            and creationDate &gt;= #{startDate}\n" +
               "        </if>\n" +
               "        <if test=\"endDate != null and endDate!=''\">\n" +
               "            and creationDate &lt;= #{endDate}\n" +
               "        </if>\n" +
               "    </trim> </script>")
       public Integer getOrderCountByMap(Map<String,Object> param);
       @Select("<script> select\n" +
               "    id as id,\n" +
               "    orderType as orderType,\n" +
               "    orderNo as orderNo,\n" +
               "    hotelId as hotelId,\n" +
               "    hotelName as hotelName,\n" +
               "    orderStatus as orderStatus,\n" +
               "    count as count,\n" +
               "    checkInDate as checkInDate,\n" +
               "    payAmount as payAmount,\n" +
               "    payType as payType,\n" +
               "    linkUserName as linkUserName,\n" +
               "    creationDate as creationDate\n" +
               "    from itrip_hotel_order\n" +
               "    <trim prefix=\"where\" prefixOverrides=\"and | or\">\n" +
               "        <if test=\"id != null and id!=''\">\n" +
               "            and id=#{id}\n" +
               "        </if>\n" +
               "        <if test=\"userId != null and userId!=''\">\n" +
               "            and userId=#{userId}\n" +
               "        </if>\n" +
               "        <if test=\"orderType != null\">\n" +
               "            and orderType=#{orderType}\n" +
               "        </if>\n" +
               "        <if test=\"orderNo != null and orderNo!=''\">\n" +
               "            and orderNo like CONCAT ('%',#{orderNo},'%')\n" +
               "        </if>\n" +
               "        <if test=\"hotelId != null and hotelId!=''\">\n" +
               "            and hotelId=#{hotelId}\n" +
               "        </if>\n" +
               "        <if test=\"hotelName != null and hotelName!=''\">\n" +
               "            and hotelName=#{hotelName}\n" +
               "        </if>\n" +
               "        <if test=\"checkInDate != null and checkInDate!=''\">\n" +
               "            and checkInDate=#{checkInDate}\n" +
               "        </if>\n" +
               "        <if test=\"orderStatus != null\">\n" +
               "            and orderStatus=#{orderStatus}\n" +
               "        </if>\n" +
               "        <if test=\"payAmount != null and payAmount!=''\">\n" +
               "            and payAmount=#{payAmount}\n" +
               "        </if>\n" +
               "        <if test=\"linkUserName != null and linkUserName != ''\">\n" +
               "            and linkUserName like CONCAT ('%',#{linkUserName},'%')\n" +
               "        </if>\n" +
               "        <if test=\"startDate != null and startDate!=''\">\n" +
               "            and creationDate &gt;= #{startDate}\n" +
               "        </if>\n" +
               "        <if test=\"endDate != null and endDate!=''\">\n" +
               "            and creationDate &lt;= #{endDate}\n" +
               "        </if>\n" +
               "    </trim>\n" +
               "    order by creationDate desc\n" +
               "    <if test=\"beginPos != null and pageSize != null  and pageSize !='' \">\n" +
               "        limit #{beginPos},#{pageSize}\n" +
               "    </if> </script>")
       public List<ItripListHotelOrderVO> getOrderListByMap(Map<String,Object> param);

       @Select("<script>" +
               " update itrip_hotel_order\n" +
               "    set orderStatus = 4,\n" +
               "    modifyDate = NOW()\n" +
               "    <if test=\"modifiedBy != null and modifiedBy!=''\">\n" +
               "        ,modifiedBy=#{modifiedBy}\n" +
               "    </if>\n" +
               "    where id=#{id}" +
               "</script>")
       public Integer updateHotelOrderStatus(@Param(value = "id")Long id, @Param(value = "modifiedBy")Long modifiedBy);

}
